<template>
    <div>
        <el-table v-loading = "loading" :data="archiveList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
             <el-table-column label = "档号" prop ="archiveCode" min-width= "30%"/>
             <el-table-column label = "题名" prop ="titleName" min-width = "40%"/>
             <el-table-column label = "密级" prop ="secretLevel" min-width = "10%">
                <template #default="scope">
                    <dict-tag :options="secret_level" :value="scope.row.secretLevel"/>
                </template>
             </el-table-column>
             <el-table-column label = "状态" prop ="borrowflag" min-width=->
                <template #default ="scope">
                    <dict-tag :options="borrow_flag" :value ="scope.row.borrowflag"/>
                </template>
             </el-table-column>
        </el-table>
        <pagination
            v-show = "total>0"
            :total = "total"
            v-model:page = "queryParams.pageNum"
            v-model:limit = "queryParams.pageSize"
            @pagination = "getList"/>
        <div class="dialog-footer">
            <el-button type="primary" @click="submit">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </div>
</template> 
<script setup>
    import { listArchive } from "@/api/archive/archive";

    const { proxy } = getCurrentInstance();
    const { secret_level,borrow_flag } = proxy.useDict('secret_level','borrow_flag');


    const emits = defineEmits(['submit','cancel']);

    const loading = ref(true);
    const archiveList = ref([]);
    const total = ref(0);
    var selectionArc = []

    const data = reactive({
        queryParams:{
            pageNum:1,
            pageSize:10,
        }
    })
    const {queryParams} = toRefs(data)

    // 查询档案列表
    function  getList() {
        loading.value = true;
        listArchive(queryParams.value).then(response =>{
            archiveList.value = response.rows;
            total.value = response.total;
            loading.value = false;
        });
    }

    function handleSelectionChange(selection) {
        selectionArc = selection
    }
    // 提交按钮
    function submit(){
        emits('submit',selectionArc)
        selectionArc = []
    }
    function cancel(){
        emits('cancel',"")
    }

    getList();
</script>